package chelydra.sharelydra.client.ui;

import chelydra.sharelydra.client.webservice.WebserviceException;
import java.awt.event.MouseEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

import java.util.Collection;
import java.util.Iterator;

import chelydra.sharelydra.client.Core;
import chelydra.sharelydra.client.database.DatabaseManager;
import chelydra.sharelydra.client.file.FileManager;
import chelydra.sharelydra.client.file.FriendFilesData;
import chelydra.sharelydra.client.file.ListFriendFilesData;
import chelydra.sharelydra.client.friend.Friend;
import chelydra.sharelydra.client.friend.FriendManager;
import chelydra.sharelydra.client.friend.Notification;
import chelydra.sharelydra.client.network.DownloadFileThread;
import chelydra.sharelydra.client.network.GetFileListThread;
import java.awt.Color;
import java.util.Date;
import java.util.Hashtable;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JTable;



/**
 * The application's main frame.
 */
public class MainView extends FrameView implements ActionListener {

	public void updateNotifications() {
		Collection<Notification> notes = Core.getApplication().getDatabaseManager().getLast15Notifications();

		DefaultTableModel model = (DefaultTableModel) this.notificationsTable.getModel();
		while ( model.getRowCount() > 0) {
			model.removeRow(0);
		}

		Iterator i = notes.iterator();
		while (i.hasNext()) {
			Notification note = (Notification)i.next();
			model.addRow(new Object[]{note.getMessage(), note.getRelativeDate(),
			note.getType(), note.getCreatedTime().getTime()});
		}

	}

    public void updateDownloadTable(String fileName,int size,String owner, String progress){
        this.emptyDownloadTable();
        progress = progress + " %";
        DefaultTableModel model = (DefaultTableModel) this.downloadsTable.getModel();
        model.addRow(new Object[]{fileName,size,owner,progress});
        this.updateTransferTablewithDownload(fileName, size, owner, progress);
    }

    public void updateTransferTablewithDownload(String fileName,int size,String owner, String progress){
        this.emptyTransferTable();
        DefaultTableModel model = (DefaultTableModel) this.transfertsTable.getModel();
        model.addRow(new Object[]{fileName,"downloading",progress});
    }

    public void updateTransferTablewithUpload(String fileName,String progress){
        this.emptyTransferTable();
        DefaultTableModel model = (DefaultTableModel) this.transfertsTable.getModel();
        model.addRow(new Object[]{fileName,"uploading",progress});
    }

    public void updateUploadTable(String fileName,String progress){
        this.emptyUploadTable();
        progress = progress + " %";
        DefaultTableModel model = (DefaultTableModel) this.uploadsTable.getModel();
        model.addRow(new Object[]{fileName,progress});
        this.updateTransferTablewithUpload(fileName,progress);
        
    }

    public void emptyDownloadTable(){
        DefaultTableModel model = (DefaultTableModel) this.downloadsTable.getModel();
        while ( model.getRowCount() > 0) {
			model.removeRow(0);
		}
    }

    public void emptyTransferTable(){
        DefaultTableModel model = (DefaultTableModel) this.transfertsTable.getModel();
        while ( model.getRowCount() > 0) {
			model.removeRow(0);
		}
        
    }

    public void emptyUploadTable(){
        DefaultTableModel model = (DefaultTableModel) this.uploadsTable.getModel();
        while ( model.getRowCount() > 0) {
			model.removeRow(0);
        }
    }

	public void updateProfile() {
		Map<String,String> map = Core.getApplication().getDatabaseManager().getUserInformation();
		this.userLoginLabel.setText(map.get("UserLogin"));
		this.lastNameTextField.setText(map.get("UserName"));
		this.firstNameTextField.setText(map.get("UserFirstname"));
		this.emailTextField.setText(map.get("UserEmail"));
		this.nicknameTextField.setText(map.get("UserNickname"));

		if ( ((String)map.get("UserHideInSearch")).contentEquals("true") )
			this.hideInSearchCheckBox.getModel().setSelected(true);
		else
			this.hideInSearchCheckBox.getModel().setSelected(false);

		if ( ((String)map.get("UserHideEmail")).contentEquals("true") )
			this.hideEmailCheckBox.getModel().setSelected(true);
		else
			this.hideEmailCheckBox.getModel().setSelected(false);

		this.profileApplyChangesButton.setEnabled(false);
		this.profileRevertChangesButton.setEnabled(false);
	}

	public void updateFriendFiles(){
		this.updateFriendFiles(ListFriendFilesData.List);
	}

	public void updateFriendFiles(Collection<FriendFilesData> files) {
		System.out.println("updateFriendFiles called");
		DefaultTableModel model = (DefaultTableModel) this.fileFriendTable.getModel();
		while(model.getRowCount() > 0){
				model.removeRow(0);
		}

		System.out.println("Number of files to add: "+files.size());
		Iterator i = files.iterator();
		while (i.hasNext()) {
			FriendFilesData ffd = (FriendFilesData)i.next();
			System.out.println("Add: "+ffd.fileName);
			Friend friend =  Core.getApplication().getFriendManager().getFriendsForLogins(ffd.friendName);
			model.addRow(new Object[]{ffd.fileName, ffd.fileSize, friend, ffd.fileId});
		}
	}

	public void updateSharedFiles(Collection<Map<String,String>> files){
		DefaultTableModel model = (DefaultTableModel) this.sharedFilesTable.getModel();
		while ( model.getRowCount() > 0){
			model.removeRow(0);
		}

		Iterator i = files.iterator();
		while (i.hasNext()) {
			Map<String,String> file = (Map<String,String>)i.next();
			model.addRow(new Object[]{file.get("FileName"),"file",file.get("FileSize"),"all"});
		}
	}
  
	public void updateFriends(Collection<Friend> friends) {
		DefaultTableModel model = (DefaultTableModel)this.myFriendsTable.getModel();
		// delete all the rows before inserting the new ones
		while (model.getRowCount()>0)
			model.removeRow(0);

		// clears the list of our connected friends
		DefaultListModel listModel = (DefaultListModel)this.connectedFriendsList.getModel();
		listModel.clear();

		// add the friends to UI
		Iterator i = friends.iterator();
		while (i.hasNext()) {
			Friend f = (Friend)i.next();
			// we add the friend in the Friends table
			model.addRow(new Object[]{f, f.getName(), f.getEmail(), f.isConnected()});
			// and the connected ones in the list on the overview panel
			if (f.isConnected())
				listModel.addElement(f);
		}

		this.removeFriendButton.setEnabled(false);
		this.getFileListButton.setEnabled(false);
	}

	public void updateSearchFriends(Collection<Map<String,String>> usersFound) {
		DefaultTableModel model = (DefaultTableModel)this.searchFriendsTable.getModel();
		// delete all the rows before doing the search
		while (model.getRowCount()>0)
			model.removeRow(0);

		// add the users found for the search to the table
		Boolean isMyFriend;
		Iterator i = usersFound.iterator();
		while (i.hasNext()) {
			Map<String,String> u = (Map<String,String>)i.next();
			isMyFriend = new Boolean(u.get("status").contentEquals("friend"));
			model.addRow(new Object[]{u.get("nickname"), u.get("name"), isMyFriend, u.get("login")});
		}

		// TODO récupérer name pour tous
	}

	public void updateGroupsTable() {
		Map<String,Integer> groups = Core.getApplication().getDatabaseManager().getGroups();

		DefaultTableModel model = (DefaultTableModel)this.groupsTable.getModel();
		// delete all the rows before doing the search
		while (model.getRowCount()>0)
			model.removeRow(0);

		String[] groupNames = groups.keySet().toArray(new String[0]);
		for (String name : groupNames) {
			model.addRow(new Object[]{name, groups.get(name)});
		}

		this.updateGroupMembers(new Vector());
		this.updateGroupNonMembers(new Vector());
	}

	public void updateGroupMembers(Collection<Friend> members) {
		DefaultListModel model = (DefaultListModel)this.groupMembersList.getModel();
		model.clear();

		Friend[] membersArray = members.toArray(new Friend[0]);
		for (Friend member : membersArray) {
			model.addElement(member);
		}
	}

	public void updateGroupNonMembers(Collection<Friend> members) {
		DefaultListModel model = (DefaultListModel)this.groupNonMembersList.getModel();
		model.clear();

		Friend[] membersArray = members.toArray(new Friend[0]);
		for (Friend member : membersArray) {
			model.addElement(member);
		}
	}

	public MainView(SingleFrameApplication app) {
		super(app);

		initComponents();

		// status bar initialization - message timeout, idle icon and busy animation, etc
		ResourceMap resourceMap = getResourceMap();
		int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
		messageTimer = new Timer(messageTimeout, new ActionListener() {
				public void actionPerformed(ActionEvent e) {
				}
		});
		messageTimer.setRepeats(false);
		int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
		for (int i = 0; i < busyIcons.length; i++) {
				busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
		}
		busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
				public void actionPerformed(ActionEvent e) {
						busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
				}
		});
		idleIcon = resourceMap.getIcon("StatusBar.idleIcon");

		// connecting action tasks to status bar via TaskMonitor
		TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
		taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
			public void propertyChange(java.beans.PropertyChangeEvent evt) {
				String propertyName = evt.getPropertyName();
				if ("started".equals(propertyName)) {
					if (!busyIconTimer.isRunning()) {
						busyIconIndex = 0;
						busyIconTimer.start();
					}
				} else if ("done".equals(propertyName)) {
					busyIconTimer.stop();
				} else if ("message".equals(propertyName)) {
					String text = (String)(evt.getNewValue());
					messageTimer.restart();
				} else if ("progress".equals(propertyName)) {
					int value = (Integer)(evt.getNewValue());
				}
			}
		});
	}

	@Action
	public void showAboutBox() {
		if (aboutBox == null) {
			JFrame mainFrame = Core.getApplication().getMainFrame();
			aboutBox = new AboutBox(mainFrame);
			aboutBox.setLocationRelativeTo(mainFrame);
		}
		Core.getApplication().show(aboutBox);
	}

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        mainTabbedPanel = new javax.swing.JTabbedPane();
        overviewPanel = new javax.swing.JPanel();
        connectedFriendScrollPane = new javax.swing.JScrollPane();
        connectedFriendsList = new javax.swing.JList();
        connectedFriendLabel = new javax.swing.JLabel();
        notificationsLabel = new javax.swing.JLabel();
        transfertLabel = new javax.swing.JLabel();
        transfertsScrollPane = new javax.swing.JScrollPane();
        transfertsTable = new javax.swing.JTable();
        jScrollPane3 = new javax.swing.JScrollPane();
        notificationsTable = new javax.swing.JTable();
        refreshOverviewButton = new javax.swing.JButton();
        transfertsPanel = new javax.swing.JPanel();
        downloadsScrollPane2 = new javax.swing.JScrollPane();
        downloadsTable = new javax.swing.JTable();
        uploadsScrollPane = new javax.swing.JScrollPane();
        uploadsTable = new javax.swing.JTable();
        transfertsSeparator = new javax.swing.JSeparator();
        downloadsLabel = new javax.swing.JLabel();
        uploadsLabel = new javax.swing.JLabel();
        friendAndGroupsPanel = new javax.swing.JPanel();
        myFriendsScrollPane = new javax.swing.JScrollPane();
        myFriendsTable = new javax.swing.JTable();
        groupsScrollPane = new javax.swing.JScrollPane();
        groupsTable = new javax.swing.JTable();
        myFriendsLabel = new javax.swing.JLabel();
        groupsLabel = new javax.swing.JLabel();
        friendsAndGroupsSeparator = new javax.swing.JSeparator();
        membersLabel = new javax.swing.JLabel();
        newGroupNameTextField = new javax.swing.JTextField();
        updateFriendsButton = new javax.swing.JButton();
        addAMemberLabel = new javax.swing.JLabel();
        createGroupButton = new javax.swing.JButton();
        addFriendToGroupButton = new javax.swing.JButton();
        removeFriendButton = new javax.swing.JButton();
        getFileListButton = new javax.swing.JButton();
        removeFriendFromGroupButton = new javax.swing.JButton();
        removeGroupButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        groupMembersList = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        groupNonMembersList = new javax.swing.JList();
        searchTabbedPanel = new javax.swing.JTabbedPane();
        searchFilesPanel = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        fileFriendTable = new javax.swing.JTable();
        downloadFileButton = new javax.swing.JButton();
        refreshButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        searchFilesKeywordsTextField = new javax.swing.JTextField();
        searchFilesButton = new javax.swing.JButton();
        searchFilesComboBox = new javax.swing.JComboBox();
        searchFilesFromComboBox = new javax.swing.JComboBox();
        clearSearchFilesButton = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        searchFriendsPanel = new javax.swing.JPanel();
        keywordsLabel = new javax.swing.JLabel();
        searchFriendsKeywordsTextField = new javax.swing.JTextField();
        searchFriendsButton = new javax.swing.JButton();
        searchFriendsResetButton = new javax.swing.JButton();
        searchResultScrollPane = new javax.swing.JScrollPane();
        searchFriendsTable = new javax.swing.JTable();
        beMyFriendButton = new javax.swing.JButton();
        sharedFilesPanel = new javax.swing.JPanel();
        sharedFilesScrollPane = new javax.swing.JScrollPane();
        sharedFilesTable = new javax.swing.JTable();
        shareAnotherFileButton = new javax.swing.JButton();
        profilePanel = new javax.swing.JPanel();
        loginLabel = new javax.swing.JLabel();
        nicknameLabel = new javax.swing.JLabel();
        firstNameLabel = new javax.swing.JLabel();
        lastNameLabel = new javax.swing.JLabel();
        emailLabel = new javax.swing.JLabel();
        nicknameTextField = new javax.swing.JTextField();
        firstNameTextField = new javax.swing.JTextField();
        lastNameTextField = new javax.swing.JTextField();
        emailTextField = new javax.swing.JTextField();
        userLoginLabel = new javax.swing.JLabel();
        hideInSearchCheckBox = new javax.swing.JCheckBox();
        hideEmailCheckBox = new javax.swing.JCheckBox();
        profileApplyChangesButton = new javax.swing.JButton();
        profileRevertChangesButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        editMenu = new javax.swing.JMenu();
        accountMenu = new javax.swing.JMenu();
        disconnectMenuItem = new javax.swing.JMenuItem();
        toolsMenu = new javax.swing.JMenu();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        jScrollPane10 = new javax.swing.JScrollPane();
        jTable6 = new javax.swing.JTable();
        friendshipProposalPopupMenu = new javax.swing.JPopupMenu();
        acceptFriendshipMenuItem = new javax.swing.JMenuItem();
        declineFriendshipMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        deleteFriendshipProposalMenuItem = new javax.swing.JMenuItem();
        defaultPopupMenu = new javax.swing.JPopupMenu();
        deleteMenuItem = new javax.swing.JMenuItem();
        sharedFilePopupMenu = new javax.swing.JPopupMenu();
        shareFileWithGroupMenu = new javax.swing.JMenu();
        shareFileWithFriendMenu = new javax.swing.JMenu();
        jSeparator2 = new javax.swing.JSeparator();
        stopSharingFileMenuItem = new javax.swing.JMenuItem();
        notifyPopupMenu = new javax.swing.JPopupMenu();
        searchSharedFileMenuItem = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        deleteNotifyMenuItem = new javax.swing.JMenuItem();

        mainPanel.setName("ShareLydra"); // NOI18N

        mainTabbedPanel.setName("mainTabbedPanel"); // NOI18N

        overviewPanel.setName("overviewPanel"); // NOI18N

        connectedFriendScrollPane.setName("connectedFriendScrollPane"); // NOI18N

        connectedFriendsList.setModel(new DefaultListModel());
        connectedFriendsList.setName("connectedFriendsList"); // NOI18N
        connectedFriendScrollPane.setViewportView(connectedFriendsList);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(chelydra.sharelydra.client.Core.class).getContext().getResourceMap(MainView.class);
        connectedFriendLabel.setText(resourceMap.getString("connectedFriendLabel.text")); // NOI18N
        connectedFriendLabel.setName("connectedFriendLabel"); // NOI18N

        notificationsLabel.setText(resourceMap.getString("notificationsLabel.text")); // NOI18N
        notificationsLabel.setName("notificationsLabel"); // NOI18N

        transfertLabel.setText(resourceMap.getString("transfertLabel.text")); // NOI18N
        transfertLabel.setName("transfertLabel"); // NOI18N

        transfertsScrollPane.setName("transfertsScrollPane"); // NOI18N

        transfertsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "name", "status", "progress"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        transfertsTable.setName("transfertsTable"); // NOI18N
        transfertsScrollPane.setViewportView(transfertsTable);
        transfertsTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("transfertsTable.columnModel.title0")); // NOI18N
        transfertsTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("transfertsTable.columnModel.title1")); // NOI18N
        transfertsTable.getColumnModel().getColumn(2).setResizable(false);
        transfertsTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("transfertsTable.columnModel.title2")); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        notificationsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Message", "Date", "type", "time"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.Long.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        notificationsTable.setName("notificationsTable"); // NOI18N
        notificationsTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                notificationsTableMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(notificationsTable);
        notificationsTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("notificationsTable.columnModel.title0")); // NOI18N
        notificationsTable.getColumnModel().getColumn(1).setPreferredWidth(10);
        notificationsTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("notificationsTable.columnModel.title1")); // NOI18N
        notificationsTable.getColumnModel().getColumn(2).setMinWidth(0);
        notificationsTable.getColumnModel().getColumn(2).setPreferredWidth(0);
        notificationsTable.getColumnModel().getColumn(2).setMaxWidth(0);
        notificationsTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("notificationsTable.columnModel.title2")); // NOI18N
        notificationsTable.getColumnModel().getColumn(3).setMinWidth(0);
        notificationsTable.getColumnModel().getColumn(3).setPreferredWidth(0);
        notificationsTable.getColumnModel().getColumn(3).setMaxWidth(0);
        notificationsTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("notificationsTable.columnModel.title3")); // NOI18N

        refreshOverviewButton.setText(resourceMap.getString("refreshOverviewButton.text")); // NOI18N
        refreshOverviewButton.setName("refreshOverviewButton"); // NOI18N
        refreshOverviewButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                updateFriendsButtonMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout overviewPanelLayout = new org.jdesktop.layout.GroupLayout(overviewPanel);
        overviewPanel.setLayout(overviewPanelLayout);
        overviewPanelLayout.setHorizontalGroup(
            overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(overviewPanelLayout.createSequentialGroup()
                .add(29, 29, 29)
                .add(overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(transfertLabel)
                    .add(overviewPanelLayout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(transfertsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 587, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(overviewPanelLayout.createSequentialGroup()
                                .add(overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                    .add(connectedFriendScrollPane, 0, 0, Short.MAX_VALUE)
                                    .add(connectedFriendLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 46, Short.MAX_VALUE)
                                .add(overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                    .add(overviewPanelLayout.createSequentialGroup()
                                        .add(notificationsLabel)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .add(refreshOverviewButton))
                                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))))
                .add(48, 48, 48))
        );
        overviewPanelLayout.setVerticalGroup(
            overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(overviewPanelLayout.createSequentialGroup()
                .add(overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(overviewPanelLayout.createSequentialGroup()
                        .add(24, 24, 24)
                        .add(overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(connectedFriendLabel)
                            .add(notificationsLabel)))
                    .add(overviewPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(refreshOverviewButton)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(overviewPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                    .add(connectedFriendScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE))
                .add(37, 37, 37)
                .add(transfertLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(transfertsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 146, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        mainTabbedPanel.addTab("Overview", overviewPanel);

        transfertsPanel.setName("transfertsPanel"); // NOI18N

        downloadsScrollPane2.setName("downloadsScrollPane2"); // NOI18N

        downloadsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "name", "size", "IPDest", "progress"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        downloadsTable.setName("downloadsTable"); // NOI18N
        downloadsScrollPane2.setViewportView(downloadsTable);
        downloadsTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("downloadsTable.columnModel.title0")); // NOI18N
        downloadsTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("downloadsTable.columnModel.title1")); // NOI18N
        downloadsTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("downloadsTable.columnModel.title2")); // NOI18N
        downloadsTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("downloadsTable.columnModel.title3")); // NOI18N

        uploadsScrollPane.setName("uploadsScrollPane"); // NOI18N

        uploadsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "name", "progress"
            }
        ));
        uploadsTable.setName("uploadsTable"); // NOI18N
        uploadsScrollPane.setViewportView(uploadsTable);
        uploadsTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("uploadsTable.columnModel.title0")); // NOI18N
        uploadsTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("uploadsTable.columnModel.title1")); // NOI18N

        transfertsSeparator.setName("transfertsSeparator"); // NOI18N

        downloadsLabel.setText(resourceMap.getString("downloadsLabel.text")); // NOI18N
        downloadsLabel.setName("downloadsLabel"); // NOI18N

        uploadsLabel.setText(resourceMap.getString("uploadsLabel.text")); // NOI18N
        uploadsLabel.setName("uploadsLabel"); // NOI18N

        org.jdesktop.layout.GroupLayout transfertsPanelLayout = new org.jdesktop.layout.GroupLayout(transfertsPanel);
        transfertsPanel.setLayout(transfertsPanelLayout);
        transfertsPanelLayout.setHorizontalGroup(
            transfertsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(transfertsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(transfertsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, transfertsPanelLayout.createSequentialGroup()
                        .add(transfertsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, uploadsScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, transfertsSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE))
                        .addContainerGap())
                    .add(downloadsLabel)
                    .add(transfertsPanelLayout.createSequentialGroup()
                        .add(downloadsScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE)
                        .addContainerGap())
                    .add(uploadsLabel)))
        );
        transfertsPanelLayout.setVerticalGroup(
            transfertsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(transfertsPanelLayout.createSequentialGroup()
                .add(downloadsLabel)
                .add(4, 4, 4)
                .add(downloadsScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 117, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 103, Short.MAX_VALUE)
                .add(transfertsSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(15, 15, 15)
                .add(uploadsLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(uploadsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 162, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        mainTabbedPanel.addTab("Transfers", transfertsPanel);

        friendAndGroupsPanel.setName("friendAndGroupsPanel"); // NOI18N

        myFriendsScrollPane.setName("myFriendsScrollPane"); // NOI18N

        myFriendsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nickname", "Name", "E-mail", "Connected"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.Boolean.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        myFriendsTable.setName("myFriendsTable"); // NOI18N
        myFriendsTable.getTableHeader().setReorderingAllowed(false);
        myFriendsTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                myFriendsTableMouseReleased(evt);
            }
        });
        myFriendsScrollPane.setViewportView(myFriendsTable);
        myFriendsTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("myFriendsTable.columnModel.title0")); // NOI18N
        myFriendsTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("myFriendsTable.columnModel.title1")); // NOI18N
        myFriendsTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("myFriendsTable.columnModel.title2")); // NOI18N
        myFriendsTable.getColumnModel().getColumn(3).setMinWidth(70);
        myFriendsTable.getColumnModel().getColumn(3).setPreferredWidth(70);
        myFriendsTable.getColumnModel().getColumn(3).setMaxWidth(70);
        myFriendsTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("myFriendsTable.columnModel.title3")); // NOI18N

        groupsScrollPane.setName("groupsScrollPane"); // NOI18N

        groupsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name", "Members"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        groupsTable.setName("groupsTable"); // NOI18N
        groupsTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                groupsTableMouseReleased(evt);
            }
        });
        groupsScrollPane.setViewportView(groupsTable);
        groupsTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("groupsTable.columnModel.title0")); // NOI18N
        groupsTable.getColumnModel().getColumn(1).setMinWidth(60);
        groupsTable.getColumnModel().getColumn(1).setPreferredWidth(60);
        groupsTable.getColumnModel().getColumn(1).setMaxWidth(60);
        groupsTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("groupsTable.columnModel.title1")); // NOI18N

        myFriendsLabel.setText(resourceMap.getString("myFriendsLabel.text")); // NOI18N
        myFriendsLabel.setName("myFriendsLabel"); // NOI18N

        groupsLabel.setText(resourceMap.getString("groupsLabel.text")); // NOI18N
        groupsLabel.setName("groupsLabel"); // NOI18N

        friendsAndGroupsSeparator.setName("friendsAndGroupsSeparator"); // NOI18N

        membersLabel.setText(resourceMap.getString("membersLabel.text")); // NOI18N
        membersLabel.setName("membersLabel"); // NOI18N

        newGroupNameTextField.setText(resourceMap.getString("newGroupNameTextField.text")); // NOI18N
        newGroupNameTextField.setName("newGroupNameTextField"); // NOI18N
        newGroupNameTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                newGroupNameTextFieldFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                newGroupNameTextFieldFocusLost(evt);
            }
        });
        newGroupNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                newGroupNameTextFieldKeyReleased(evt);
            }
        });

        updateFriendsButton.setText(resourceMap.getString("updateFriendsButton.text")); // NOI18N
        updateFriendsButton.setName("updateFriendsButton"); // NOI18N
        updateFriendsButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                updateFriendsButtonMouseClicked(evt);
            }
        });

        addAMemberLabel.setText(resourceMap.getString("addAMemberLabel.text")); // NOI18N
        addAMemberLabel.setName("addAMemberLabel"); // NOI18N

        createGroupButton.setText(resourceMap.getString("createGroupButton.text")); // NOI18N
        createGroupButton.setEnabled(false);
        createGroupButton.setName("createGroupButton"); // NOI18N
        createGroupButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                createGroupButtonMouseClicked(evt);
            }
        });

        addFriendToGroupButton.setText(resourceMap.getString("addFriendToGroupButton.text")); // NOI18N
        addFriendToGroupButton.setEnabled(false);
        addFriendToGroupButton.setName("addFriendToGroupButton"); // NOI18N
        addFriendToGroupButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addFriendToGroupButtonMouseClicked(evt);
            }
        });

        removeFriendButton.setText(resourceMap.getString("removeFriendButton.text")); // NOI18N
        removeFriendButton.setEnabled(false);
        removeFriendButton.setName("removeFriendButton"); // NOI18N
        removeFriendButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                removeFriendButtonMouseClicked(evt);
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(chelydra.sharelydra.client.Core.class).getContext().getActionMap(MainView.class, this);
        getFileListButton.setAction(actionMap.get("GetFileListofUser")); // NOI18N
        getFileListButton.setText(resourceMap.getString("getFileListButton.text")); // NOI18N
        getFileListButton.setName("getFileListButton"); // NOI18N
        getFileListButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getFileListButtonActionPerformed(evt);
            }
        });

        removeFriendFromGroupButton.setText(resourceMap.getString("removeFriendFromGroupButton.text")); // NOI18N
        removeFriendFromGroupButton.setEnabled(false);
        removeFriendFromGroupButton.setName("removeFriendFromGroupButton"); // NOI18N
        removeFriendFromGroupButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                removeFriendFromGroupButtonMouseClicked(evt);
            }
        });

        removeGroupButton.setText(resourceMap.getString("removeGroupButton.text")); // NOI18N
        removeGroupButton.setEnabled(false);
        removeGroupButton.setName("removeGroupButton"); // NOI18N
        removeGroupButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                removeGroupButtonMouseClicked(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        groupMembersList.setModel(new DefaultListModel());
        groupMembersList.setName("groupMembersList"); // NOI18N
        groupMembersList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                groupMembersListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(groupMembersList);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        groupNonMembersList.setModel(new DefaultListModel());
        groupNonMembersList.setName("groupNonMembersList"); // NOI18N
        groupNonMembersList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                groupNonMembersListMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(groupNonMembersList);

        org.jdesktop.layout.GroupLayout friendAndGroupsPanelLayout = new org.jdesktop.layout.GroupLayout(friendAndGroupsPanel);
        friendAndGroupsPanel.setLayout(friendAndGroupsPanelLayout);
        friendAndGroupsPanelLayout.setHorizontalGroup(
            friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(friendAndGroupsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(friendAndGroupsPanelLayout.createSequentialGroup()
                        .add(updateFriendsButton)
                        .add(289, 289, 289)
                        .add(getFileListButton)
                        .add(18, 18, 18)
                        .add(removeFriendButton))
                    .add(myFriendsLabel)
                    .add(friendAndGroupsPanelLayout.createSequentialGroup()
                        .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(groupsLabel)
                            .add(friendAndGroupsPanelLayout.createSequentialGroup()
                                .add(newGroupNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 135, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(createGroupButton)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                                .add(removeGroupButton))
                            .add(groupsScrollPane, 0, 0, Short.MAX_VALUE))
                        .add(14, 14, 14)
                        .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(friendAndGroupsPanelLayout.createSequentialGroup()
                                .add(21, 21, 21)
                                .add(removeFriendFromGroupButton))
                            .add(friendAndGroupsPanelLayout.createSequentialGroup()
                                .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 114, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                    .add(membersLabel))
                                .add(41, 41, 41)
                                .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(addAMemberLabel)
                                    .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                        .add(addFriendToGroupButton)
                                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 113, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))))
                    .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, friendsAndGroupsSeparator)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, myFriendsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 610, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(18, 18, 18))
        );
        friendAndGroupsPanelLayout.setVerticalGroup(
            friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, friendAndGroupsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(myFriendsLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(myFriendsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 121, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(updateFriendsButton)
                    .add(getFileListButton)
                    .add(removeFriendButton))
                .add(15, 15, 15)
                .add(friendsAndGroupsSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(8, 8, 8)
                .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(groupsLabel)
                    .add(membersLabel)
                    .add(addAMemberLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                    .add(groupsScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 174, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(friendAndGroupsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(newGroupNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(removeGroupButton)
                    .add(createGroupButton)
                    .add(removeFriendFromGroupButton)
                    .add(addFriendToGroupButton))
                .addContainerGap())
        );

        mainTabbedPanel.addTab("Friends & Groups", friendAndGroupsPanel);

        searchTabbedPanel.setName("searchTabbedPanel"); // NOI18N

        searchFilesPanel.setName("searchFilesPanel"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        fileFriendTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Filename", "Size", "Owner", "FileId"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.Integer.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        fileFriendTable.setName("fileFriendTable"); // NOI18N
        fileFriendTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                fileFriendTableMouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(fileFriendTable);
        fileFriendTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("fileFriendTable.columnModel.title0")); // NOI18N
        fileFriendTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("fileFriendTable.columnModel.title1")); // NOI18N
        fileFriendTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("fileFriendTable.columnModel.title2")); // NOI18N
        fileFriendTable.getColumnModel().getColumn(3).setMinWidth(0);
        fileFriendTable.getColumnModel().getColumn(3).setPreferredWidth(0);
        fileFriendTable.getColumnModel().getColumn(3).setMaxWidth(0);
        fileFriendTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("fileFriendTable.columnModel.title3")); // NOI18N

        downloadFileButton.setText(resourceMap.getString("downloadFileButton.text")); // NOI18N
        downloadFileButton.setEnabled(false);
        downloadFileButton.setName("downloadFileButton"); // NOI18N
        downloadFileButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                downloadFileButtonMouseClicked(evt);
            }
        });

        refreshButton.setText(resourceMap.getString("refreshButton.text")); // NOI18N
        refreshButton.setEnabled(false);
        refreshButton.setName("refreshButton"); // NOI18N
        refreshButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionPerformedrefreshButton(evt);
            }
        });

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        searchFilesKeywordsTextField.setText(resourceMap.getString("searchFilesKeywordsTextField.text")); // NOI18N
        searchFilesKeywordsTextField.setName("searchFilesKeywordsTextField"); // NOI18N

        searchFilesButton.setText(resourceMap.getString("searchFilesButton.text")); // NOI18N
        searchFilesButton.setName("searchFilesButton"); // NOI18N
        searchFilesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchFilesButtonActionPerformed(evt);
            }
        });

        searchFilesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Everyone", "Group", "Friend" }));
        searchFilesComboBox.setName("searchFilesComboBox"); // NOI18N
        searchFilesComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchFilesComboBoxActionPerformed(evt);
            }
        });

        searchFilesFromComboBox.setModel(new DefaultComboBoxModel());
        searchFilesFromComboBox.setEnabled(false);
        searchFilesFromComboBox.setName("searchFilesFromComboBox"); // NOI18N

        clearSearchFilesButton.setText(resourceMap.getString("clearSearchFilesButton.text")); // NOI18N
        clearSearchFilesButton.setName("clearSearchFilesButton"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        org.jdesktop.layout.GroupLayout searchFilesPanelLayout = new org.jdesktop.layout.GroupLayout(searchFilesPanel);
        searchFilesPanel.setLayout(searchFilesPanelLayout);
        searchFilesPanelLayout.setHorizontalGroup(
            searchFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, searchFilesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(searchFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, searchFilesPanelLayout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(searchFilesKeywordsTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 139, Short.MAX_VALUE)
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(searchFilesComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(searchFilesFromComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 118, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(searchFilesButton))
                    .add(searchFilesPanelLayout.createSequentialGroup()
                        .add(clearSearchFilesButton)
                        .add(12, 12, 12)
                        .add(refreshButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 400, Short.MAX_VALUE)
                        .add(downloadFileButton)))
                .addContainerGap())
        );
        searchFilesPanelLayout.setVerticalGroup(
            searchFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(searchFilesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(searchFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(searchFilesKeywordsTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(searchFilesButton)
                    .add(searchFilesFromComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(searchFilesComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 76, Short.MAX_VALUE)
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 270, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(searchFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(downloadFileButton)
                    .add(refreshButton)
                    .add(clearSearchFilesButton))
                .addContainerGap())
        );

        searchTabbedPanel.addTab("Files", searchFilesPanel);

        searchFriendsPanel.setName("searchFriendsPanel"); // NOI18N

        keywordsLabel.setText(resourceMap.getString("keywordsLabel.text")); // NOI18N
        keywordsLabel.setName("keywordsLabel"); // NOI18N

        searchFriendsKeywordsTextField.setName("searchFriendsKeywordsTextField"); // NOI18N
        searchFriendsKeywordsTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                searchFriendsKeywordsTextFieldKeyReleased(evt);
            }
        });

        searchFriendsButton.setText(resourceMap.getString("searchFriendsButton.text")); // NOI18N
        searchFriendsButton.setEnabled(false);
        searchFriendsButton.setName("searchFriendsButton"); // NOI18N
        searchFriendsButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                searchFriendsButtonMouseClicked(evt);
            }
        });

        searchFriendsResetButton.setText(resourceMap.getString("searchFriendsResetButton.text")); // NOI18N
        searchFriendsResetButton.setName("searchFriendsResetButton"); // NOI18N
        searchFriendsResetButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                searchFriendsResetButtonMouseClicked(evt);
            }
        });

        searchResultScrollPane.setName("searchResultScrollPane"); // NOI18N

        searchFriendsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nickname", "Name", "Is my friend", "login"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Boolean.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        searchFriendsTable.setName("searchFriendsTable"); // NOI18N
        searchFriendsTable.getTableHeader().setReorderingAllowed(false);
        searchFriendsTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                searchFriendsTableMouseReleased(evt);
            }
        });
        searchResultScrollPane.setViewportView(searchFriendsTable);
        searchFriendsTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("searchFriendsTable.columnModel.title0")); // NOI18N
        searchFriendsTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("searchFriendsTable.columnModel.title1")); // NOI18N
        searchFriendsTable.getColumnModel().getColumn(2).setMinWidth(80);
        searchFriendsTable.getColumnModel().getColumn(2).setPreferredWidth(80);
        searchFriendsTable.getColumnModel().getColumn(2).setMaxWidth(80);
        searchFriendsTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("searchFriendsTable.columnModel.title2")); // NOI18N
        searchFriendsTable.getColumnModel().getColumn(3).setMinWidth(0);
        searchFriendsTable.getColumnModel().getColumn(3).setPreferredWidth(0);
        searchFriendsTable.getColumnModel().getColumn(3).setMaxWidth(0);
        searchFriendsTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("searchFriendsTable.columnModel.title3")); // NOI18N

        beMyFriendButton.setText(resourceMap.getString("beMyFriendButton.text")); // NOI18N
        beMyFriendButton.setEnabled(false);
        beMyFriendButton.setName("beMyFriendButton"); // NOI18N
        beMyFriendButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                beMyFriendButtonMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout searchFriendsPanelLayout = new org.jdesktop.layout.GroupLayout(searchFriendsPanel);
        searchFriendsPanel.setLayout(searchFriendsPanelLayout);
        searchFriendsPanelLayout.setHorizontalGroup(
            searchFriendsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, searchFriendsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(searchFriendsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(beMyFriendButton)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, searchResultScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, searchFriendsPanelLayout.createSequentialGroup()
                        .add(keywordsLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(searchFriendsKeywordsTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 161, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(29, 29, 29)
                        .add(searchFriendsButton)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(searchFriendsResetButton)))
                .addContainerGap())
        );
        searchFriendsPanelLayout.setVerticalGroup(
            searchFriendsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(searchFriendsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(searchFriendsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(keywordsLabel)
                    .add(searchFriendsKeywordsTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(searchFriendsButton)
                    .add(searchFriendsResetButton))
                .add(18, 18, 18)
                .add(searchResultScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 235, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(beMyFriendButton)
                .addContainerGap(92, Short.MAX_VALUE))
        );

        searchTabbedPanel.addTab("Friends", searchFriendsPanel);

        mainTabbedPanel.addTab("Search", searchTabbedPanel);

        sharedFilesPanel.setName("sharedFilesPanel"); // NOI18N

        sharedFilesScrollPane.setName("sharedFilesScrollPane"); // NOI18N

        sharedFilesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "name", "type", "size", "rights"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        sharedFilesTable.setName("sharedFilesTable"); // NOI18N
        sharedFilesTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sharedFilesTableMouseClicked(evt);
            }
        });
        sharedFilesScrollPane.setViewportView(sharedFilesTable);
        sharedFilesTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("sharedFilesTable.columnModel.title0")); // NOI18N
        sharedFilesTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("sharedFilesTable.columnModel.title1")); // NOI18N
        sharedFilesTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("sharedFilesTable.columnModel.title2")); // NOI18N
        sharedFilesTable.getColumnModel().getColumn(3).setMinWidth(0);
        sharedFilesTable.getColumnModel().getColumn(3).setPreferredWidth(0);
        sharedFilesTable.getColumnModel().getColumn(3).setMaxWidth(0);
        sharedFilesTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("sharedFilesTable.columnModel.title3")); // NOI18N

        shareAnotherFileButton.setText(resourceMap.getString("shareAnotherFileButton.text")); // NOI18N
        shareAnotherFileButton.setName("shareAnotherFileButton"); // NOI18N
        shareAnotherFileButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                shareAnotherFileButtonMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout sharedFilesPanelLayout = new org.jdesktop.layout.GroupLayout(sharedFilesPanel);
        sharedFilesPanel.setLayout(sharedFilesPanelLayout);
        sharedFilesPanelLayout.setHorizontalGroup(
            sharedFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sharedFilesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(sharedFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(sharedFilesScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 644, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, shareAnotherFileButton))
                .addContainerGap())
        );
        sharedFilesPanelLayout.setVerticalGroup(
            sharedFilesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(sharedFilesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(sharedFilesScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 293, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 79, Short.MAX_VALUE)
                .add(shareAnotherFileButton)
                .add(42, 42, 42))
        );

        mainTabbedPanel.addTab("Shared files", sharedFilesPanel);

        profilePanel.setName("profilePanel"); // NOI18N

        loginLabel.setText(resourceMap.getString("loginLabel.text")); // NOI18N
        loginLabel.setName("loginLabel"); // NOI18N

        nicknameLabel.setText(resourceMap.getString("nicknameLabel.text")); // NOI18N
        nicknameLabel.setName("nicknameLabel"); // NOI18N

        firstNameLabel.setText(resourceMap.getString("firstNameLabel.text")); // NOI18N
        firstNameLabel.setName("firstNameLabel"); // NOI18N

        lastNameLabel.setText(resourceMap.getString("lastNameLabel.text")); // NOI18N
        lastNameLabel.setName("lastNameLabel"); // NOI18N

        emailLabel.setText(resourceMap.getString("emailLabel.text")); // NOI18N
        emailLabel.setName("emailLabel"); // NOI18N

        nicknameTextField.setName("nicknameTextField"); // NOI18N
        nicknameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                profileTextFieldKeyReleased(evt);
            }
        });

        firstNameTextField.setName("firstNameTextField"); // NOI18N
        firstNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                profileTextFieldKeyReleased(evt);
            }
        });

        lastNameTextField.setName("lastNameTextField"); // NOI18N
        lastNameTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                profileTextFieldKeyReleased(evt);
            }
        });

        emailTextField.setName("emailTextField"); // NOI18N
        emailTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                profileTextFieldKeyReleased(evt);
            }
        });

        userLoginLabel.setText(resourceMap.getString("userLoginLabel.text")); // NOI18N
        userLoginLabel.setName("userLoginLabel"); // NOI18N

        hideInSearchCheckBox.setText(resourceMap.getString("hideInSearchCheckBox.text")); // NOI18N
        hideInSearchCheckBox.setName("hideInSearchCheckBox"); // NOI18N
        hideInSearchCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                profileCheckBoxActionPerformed(evt);
            }
        });

        hideEmailCheckBox.setText(resourceMap.getString("hideEmailCheckBox.text")); // NOI18N
        hideEmailCheckBox.setName("hideEmailCheckBox"); // NOI18N
        hideEmailCheckBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                profileCheckBoxActionPerformed(evt);
            }
        });

        profileApplyChangesButton.setText(resourceMap.getString("profileApplyChangesButton.text")); // NOI18N
        profileApplyChangesButton.setEnabled(false);
        profileApplyChangesButton.setName("profileApplyChangesButton"); // NOI18N
        profileApplyChangesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                profileApplyChangesButtonMouseClicked(evt);
            }
        });

        profileRevertChangesButton.setText(resourceMap.getString("profileRevertChangesButton.text")); // NOI18N
        profileRevertChangesButton.setEnabled(false);
        profileRevertChangesButton.setName("profileRevertChangesButton"); // NOI18N
        profileRevertChangesButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                profileRevertChangesButtonMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout profilePanelLayout = new org.jdesktop.layout.GroupLayout(profilePanel);
        profilePanel.setLayout(profilePanelLayout);
        profilePanelLayout.setHorizontalGroup(
            profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(profilePanelLayout.createSequentialGroup()
                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(profilePanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(loginLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 101, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(profilePanelLayout.createSequentialGroup()
                                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                        .add(lastNameLabel)
                                        .add(org.jdesktop.layout.GroupLayout.TRAILING, profilePanelLayout.createSequentialGroup()
                                            .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                                .add(org.jdesktop.layout.GroupLayout.LEADING, nicknameLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)
                                                .add(firstNameLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE))
                                            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                                    .add(profilePanelLayout.createSequentialGroup()
                                        .add(emailLabel)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                                        .add(lastNameTextField)
                                        .add(emailTextField)
                                        .add(firstNameTextField)
                                        .add(nicknameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 219, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                                    .add(userLoginLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                        .add(182, 182, 182))
                    .add(profilePanelLayout.createSequentialGroup()
                        .add(40, 40, 40)
                        .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(hideEmailCheckBox)
                            .add(hideInSearchCheckBox))
                        .add(286, 286, 286)))
                .add(132, 132, 132))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, profilePanelLayout.createSequentialGroup()
                .addContainerGap(386, Short.MAX_VALUE)
                .add(profileRevertChangesButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(profileApplyChangesButton)
                .add(56, 56, 56))
        );
        profilePanelLayout.setVerticalGroup(
            profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(profilePanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(profilePanelLayout.createSequentialGroup()
                        .add(userLoginLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(nicknameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(profilePanelLayout.createSequentialGroup()
                        .add(loginLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(nicknameLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(firstNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(firstNameLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(5, 5, 5)
                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lastNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(lastNameLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(emailTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 32, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(emailLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(30, 30, 30)
                .add(hideInSearchCheckBox)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(hideEmailCheckBox)
                .add(67, 67, 67)
                .add(profilePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(profileRevertChangesButton)
                    .add(profileApplyChangesButton))
                .add(47, 47, 47))
        );

        mainTabbedPanel.addTab("Profile", profilePanel);

        org.jdesktop.layout.GroupLayout mainPanelLayout = new org.jdesktop.layout.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(mainTabbedPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 669, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(mainPanelLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(mainTabbedPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 476, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        editMenu.setText(resourceMap.getString("editMenu.text")); // NOI18N
        editMenu.setName("editMenu"); // NOI18N
        menuBar.add(editMenu);

        accountMenu.setText(resourceMap.getString("accountMenu.text")); // NOI18N
        accountMenu.setName("accountMenu"); // NOI18N

        disconnectMenuItem.setAction(actionMap.get("disconnect")); // NOI18N
        disconnectMenuItem.setText(resourceMap.getString("disconnectMenuItem.text")); // NOI18N
        disconnectMenuItem.setName("disconnectMenuItem"); // NOI18N
        accountMenu.add(disconnectMenuItem);

        menuBar.add(accountMenu);

        toolsMenu.setText(resourceMap.getString("toolsMenu.text")); // NOI18N
        toolsMenu.setName("toolsMenu"); // NOI18N
        menuBar.add(toolsMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        jScrollPane10.setName("jScrollPane10"); // NOI18N

        jTable6.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable6.setName("jTable6"); // NOI18N
        jScrollPane10.setViewportView(jTable6);

        friendshipProposalPopupMenu.setName("friendshipProposalPopupMenu"); // NOI18N

        acceptFriendshipMenuItem.setAction(actionMap.get("acceptFriendshipProposal")); // NOI18N
        acceptFriendshipMenuItem.setText(resourceMap.getString("acceptFriendshipMenuItem.text")); // NOI18N
        acceptFriendshipMenuItem.setName("acceptFriendshipMenuItem"); // NOI18N
        friendshipProposalPopupMenu.add(acceptFriendshipMenuItem);

        declineFriendshipMenuItem.setAction(actionMap.get("declineFriendshipProposal")); // NOI18N
        declineFriendshipMenuItem.setText(resourceMap.getString("declineFriendshipMenuItem.text")); // NOI18N
        declineFriendshipMenuItem.setName("declineFriendshipMenuItem"); // NOI18N
        friendshipProposalPopupMenu.add(declineFriendshipMenuItem);

        jSeparator1.setName("jSeparator1"); // NOI18N
        friendshipProposalPopupMenu.add(jSeparator1);

        deleteFriendshipProposalMenuItem.setAction(actionMap.get("deleteNotification")); // NOI18N
        deleteFriendshipProposalMenuItem.setText(resourceMap.getString("deleteFriendshipProposalMenuItem.text")); // NOI18N
        deleteFriendshipProposalMenuItem.setName("deleteFriendshipProposalMenuItem"); // NOI18N
        friendshipProposalPopupMenu.add(deleteFriendshipProposalMenuItem);

        defaultPopupMenu.setName("defaultPopupMenu"); // NOI18N

        deleteMenuItem.setAction(actionMap.get("deleteNotification")); // NOI18N
        deleteMenuItem.setText(resourceMap.getString("deleteMenuItem.text")); // NOI18N
        deleteMenuItem.setName("deleteMenuItem"); // NOI18N
        defaultPopupMenu.add(deleteMenuItem);

        sharedFilePopupMenu.setName("sharedFilePopupMenu"); // NOI18N

        shareFileWithGroupMenu.setText(resourceMap.getString("shareFileWithGroupMenu.text")); // NOI18N
        shareFileWithGroupMenu.setName("shareFileWithGroupMenu"); // NOI18N
        sharedFilePopupMenu.add(shareFileWithGroupMenu);

        shareFileWithFriendMenu.setText(resourceMap.getString("shareFileWithFriendMenu.text")); // NOI18N
        shareFileWithFriendMenu.setName("shareFileWithFriendMenu"); // NOI18N
        sharedFilePopupMenu.add(shareFileWithFriendMenu);

        jSeparator2.setName("jSeparator2"); // NOI18N
        sharedFilePopupMenu.add(jSeparator2);

        stopSharingFileMenuItem.setText(resourceMap.getString("stopSharingFileMenuItem.text")); // NOI18N
        stopSharingFileMenuItem.setName("stopSharingFileMenuItem"); // NOI18N
        stopSharingFileMenuItem.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                stopSharingFileMenuItemMouseClicked(evt);
            }
        });
        stopSharingFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopSharingFileMenuItemActionPerformed(evt);
            }
        });
        sharedFilePopupMenu.add(stopSharingFileMenuItem);

        notifyPopupMenu.setName("notifyPopupMenu"); // NOI18N

        searchSharedFileMenuItem.setAction(actionMap.get("searchSharedFileAction")); // NOI18N
        searchSharedFileMenuItem.setText(resourceMap.getString("searchSharedFileMenuItem.text")); // NOI18N
        searchSharedFileMenuItem.setName("searchSharedFileMenuItem"); // NOI18N
        notifyPopupMenu.add(searchSharedFileMenuItem);

        jSeparator3.setName("jSeparator3"); // NOI18N
        notifyPopupMenu.add(jSeparator3);

        deleteNotifyMenuItem.setAction(actionMap.get("deleteNotification")); // NOI18N
        deleteNotifyMenuItem.setText(resourceMap.getString("deleteNotifyMenuItem.text")); // NOI18N
        deleteNotifyMenuItem.setName("deleteNotifyMenuItem"); // NOI18N
        notifyPopupMenu.add(deleteNotifyMenuItem);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

	private boolean nameMatchesKeywords(String name, Collection<String> keywords) {
		int matching = 0;

		String[] words = keywords.toArray(new String[keywords.size()]);
		for (String word : words) {
			if (name.contains(word))
				matching++;
		}

		return (matching==words.length);
	}

	private void searchFriendFiles(String keyword) {
		Collection<FriendFilesData> files = new Vector();

		Collection<String> keywords = new Vector();
		StringTokenizer st =new StringTokenizer(keyword.toLowerCase()," ");
		while (st.hasMoreTokens()){
      keywords.add(st.nextToken());
    }
		
		Iterator i = ListFriendFilesData.List.iterator();
		while (i.hasNext()) {
			FriendFilesData ffd = (FriendFilesData)i.next();
			if (this.nameMatchesKeywords(ffd.fileName.toLowerCase(), keywords)){
				files.add(ffd);
			}
		}
		
		this.updateFriendFiles(files);
	}

	private void searchFriendFiles(String keyword, Collection<String> logins) {
		Collection<FriendFilesData> files = new Vector();

		Collection<String> keywords = new Vector();
		StringTokenizer st =new StringTokenizer(keyword.toLowerCase()," ");
		while (st.hasMoreTokens()){
      keywords.add(st.nextToken());
    }

		Iterator i = ListFriendFilesData.List.iterator();
		while (i.hasNext()) {
			FriendFilesData ffd = (FriendFilesData)i.next();
			if (this.nameMatchesKeywords(ffd.fileName.toLowerCase(), keywords) && logins.contains(ffd.friendName)){
				files.add(ffd);
			}
		}

		this.updateFriendFiles(files);
	}

		private void updateFriendsButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_updateFriendsButtonMouseClicked
			Core.getApplication().getFriendManager().updateFriends();
			this.updateNotifications();
}//GEN-LAST:event_updateFriendsButtonMouseClicked

		private void searchFriendsTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_searchFriendsTableMouseReleased
			if (this.searchFriendsTable.getSelectedRowCount()==1) {
				String selectedLogin = (String)this.searchFriendsTable.getModel().getValueAt(this.searchFriendsTable.getSelectedRow(), 3);

				if (!Core.getApplication().getFriendManager().isMyFriend(selectedLogin))
					this.beMyFriendButton.setEnabled(true);
				else
					this.beMyFriendButton.setEnabled(false);
				
			} else {
				this.beMyFriendButton.setEnabled(false);
			}
		}//GEN-LAST:event_searchFriendsTableMouseReleased

		private void searchFriendsKeywordsTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_searchFriendsKeywordsTextFieldKeyReleased
			if (this.searchFriendsKeywordsTextField.getText().length()>0) {
				this.searchFriendsButton.setEnabled(true);
			} else {
				this.searchFriendsButton.setEnabled(false);
			}
}//GEN-LAST:event_searchFriendsKeywordsTextFieldKeyReleased

		private void searchFriendsButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_searchFriendsButtonMouseClicked
			if (this.searchFriendsButton.isEnabled()) {
				DefaultTableModel model = (DefaultTableModel)this.searchFriendsTable.getModel();
				// delete all the rows before doing the search
				while (model.getRowCount()>0)
					model.removeRow(0);

				Core.getApplication().getFriendManager().searchFriends(this.searchFriendsKeywordsTextField.getText());
			}
		}//GEN-LAST:event_searchFriendsButtonMouseClicked

		private void searchFriendsResetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_searchFriendsResetButtonMouseClicked
			DefaultTableModel model = (DefaultTableModel)this.searchFriendsTable.getModel();
			// delete all the rows before doing the search
			while (model.getRowCount()>0)
				model.removeRow(0);

			this.searchFriendsKeywordsTextField.setText("");
			this.searchFriendsButton.setEnabled(false);
			this.beMyFriendButton.setEnabled(false);
		}//GEN-LAST:event_searchFriendsResetButtonMouseClicked

		private void beMyFriendButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_beMyFriendButtonMouseClicked
			if (this.beMyFriendButton.isEnabled()) {
				DefaultTableModel model = (DefaultTableModel)this.searchFriendsTable.getModel();
				String selectedLogin = (String)model.getValueAt(this.searchFriendsTable.getSelectedRow(), 3);
				String selectedNickname = (String)model.getValueAt(this.searchFriendsTable.getSelectedRow(), 0);

				try {
					Core.getApplication().getWebserviceManager().doPropose(selectedLogin);

					DatabaseManager dbm = Core.getApplication().getDatabaseManager();
					Notification newNote = new Notification(new Date(), Notification.SENT_FRIENDSHIP_PROPOSAL,
									"", selectedLogin, selectedNickname, this.loginLabel.getText());
					dbm.addNewNotification(newNote);
					this.updateNotifications();

				} catch (WebserviceException ex) {
					Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
				}
			}
		}//GEN-LAST:event_beMyFriendButtonMouseClicked

		private void myFriendsTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_myFriendsTableMouseReleased
			if (this.myFriendsTable.getSelectedRowCount()==1) {
                this.getFileListButton.setEnabled(true);
				this.removeFriendButton.setEnabled(true);

			} else {
                this.getFileListButton.setEnabled(false);
				this.removeFriendButton.setEnabled(false);
			}
		}//GEN-LAST:event_myFriendsTableMouseReleased

		private void newGroupNameTextFieldFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_newGroupNameTextFieldFocusGained
			this.newGroupNameTextField.setForeground(new Color(0,0,0));
			if (this.newGroupNameTextField.getText().contentEquals("New group name")) {
				this.newGroupNameTextField.setText("");
			}
		}//GEN-LAST:event_newGroupNameTextFieldFocusGained

		private void newGroupNameTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_newGroupNameTextFieldFocusLost
			this.newGroupNameTextField.setForeground(new Color(153,153,153));
			if (this.newGroupNameTextField.getText().length()<1) {
				this.newGroupNameTextField.setText("New group name");
			}
		}//GEN-LAST:event_newGroupNameTextFieldFocusLost

		private void newGroupNameTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_newGroupNameTextFieldKeyReleased
			System.err.println(Core.getApplication().getDatabaseManager().getGroups());


			String newGroupName = this.newGroupNameTextField.getText();
			if (newGroupName.length()>0) {
				if (Core.getApplication().getDatabaseManager().groupAlreadyExists(newGroupName)) {
					this.createGroupButton.setEnabled(false);
				} else {
					this.createGroupButton.setEnabled(true);
				}

			} else {
				this.createGroupButton.setEnabled(false);
			}
		}//GEN-LAST:event_newGroupNameTextFieldKeyReleased

		private void createGroupButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_createGroupButtonMouseClicked
			if (this.createGroupButton.isEnabled()) {
				DatabaseManager dbm = Core.getApplication().getDatabaseManager();
				dbm.addNewGroup(this.newGroupNameTextField.getText());
				this.updateGroupsTable();
				this.newGroupNameTextField.setText("New group name");
				this.createGroupButton.setEnabled(false);
			}
		}//GEN-LAST:event_createGroupButtonMouseClicked

        private void getFileListButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getFileListButtonActionPerformed
            // Sequence where the File from another user will be downloaded.
            System.out.println(this.connectedFriendsList.getSelectedValue());
            this.myFriendsTable.getSelectedRow();
            Friend selectedFriend = (Friend)this.myFriendsTable.getModel().getValueAt(this.myFriendsTable.getSelectedRow(), 0);
            FriendManager fm = Core.getApplication().getFriendManager();
            String ipDest = fm.getIpForLogin(selectedFriend.getLogin());
            int port = fm.getPortForLogin(selectedFriend.getLogin());
            System.out.println("Login "+selectedFriend.getLogin() +"  IPDest"+ipDest + " port "+port );
            try{
                GetFileListThread gFLT = new GetFileListThread(ipDest,port,selectedFriend.getLogin());
                gFLT.start();

            }catch(Exception e){
                System.out.println("Error while trying to get the File List");                
            }
            //To do go on, by using the friend manager methods to get IP and ports from a login Name.
            
            
            System.out.println("Click sur le bouton");
        }//GEN-LAST:event_getFileListButtonActionPerformed

				private void groupsTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_groupsTableMouseReleased
					if (this.groupsTable.getSelectedRowCount()==1) {
						String selectedGroup = (String)this.groupsTable.getModel().getValueAt(this.groupsTable.getSelectedRow(), 0);

						Collection<Friend> members = Core.getApplication().getFriendManager().getFriendsOfGroup(selectedGroup);
						this.updateGroupMembers(members);

						Collection<Friend> nonMembers = Core.getApplication().getFriendManager().getNonFriendsOfGroup(selectedGroup);
						this.updateGroupNonMembers(nonMembers);

						this.removeGroupButton.setEnabled(true);

					} else {
						this.removeGroupButton.setEnabled(false);
					}
				}//GEN-LAST:event_groupsTableMouseReleased

				private void removeGroupButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeGroupButtonMouseClicked
					if (this.removeGroupButton.isEnabled()) {
						String selectedGroup = (String)this.groupsTable.getModel().getValueAt(this.groupsTable.getSelectedRow(), 0);
						Core.getApplication().getDatabaseManager().deleteGroup(selectedGroup);
						this.updateGroupsTable();
						this.removeGroupButton.setEnabled(false);
					}
				}//GEN-LAST:event_removeGroupButtonMouseClicked

                private void shareAnotherFileButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_shareAnotherFileButtonMouseClicked
									JFileChooser chooser = new JFileChooser();
									chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
									int returnVal = chooser.showOpenDialog(this.shareAnotherFileButton);
									if(returnVal == JFileChooser.APPROVE_OPTION) {
										 System.out.println("dossier a lister :"+chooser.getSelectedFile().getAbsolutePath());
										 FileManager.listing(chooser.getSelectedFile().getAbsolutePath());
										 FileManager.updateFileUI();
									}
                }//GEN-LAST:event_shareAnotherFileButtonMouseClicked

								private void profileTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_profileTextFieldKeyReleased
									this.profileRevertChangesButton.setEnabled(true);
									this.profileApplyChangesButton.setEnabled(false);
									if (this.nicknameTextField.getText().length()>0)
										if (this.firstNameTextField.getText().length()>0)
											if (this.lastNameTextField.getText().length()>0)
												if (this.emailTextField.getText().length()>0)
													this.profileApplyChangesButton.setEnabled(true);
								}//GEN-LAST:event_profileTextFieldKeyReleased

								private void profileRevertChangesButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_profileRevertChangesButtonMouseClicked
									this.updateProfile();
								}//GEN-LAST:event_profileRevertChangesButtonMouseClicked

								private void profileApplyChangesButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_profileApplyChangesButtonMouseClicked
									Map<String,String> parameters = new Hashtable(4);
									parameters.put("nickname", this.nicknameTextField.getText());
									parameters.put("firstName", this.firstNameTextField.getText());
									parameters.put("lastName", this.lastNameTextField.getText());
									parameters.put("email", this.emailTextField.getText());

									if (this.hideInSearchCheckBox.getModel().isSelected())
										parameters.put("hideInSearch", "true");
									else
										parameters.put("hideInSearch", "false");

									if (this.hideEmailCheckBox.getModel().isSelected())
										parameters.put("hideEmail", "true");
									else
										parameters.put("hideEmail", "false");

									try {
										Core.getApplication().getWebserviceManager().doProfile(parameters);
									} catch (WebserviceException ex) {
										ex.printStackTrace(System.err);
										this.updateProfile();
									}
								}//GEN-LAST:event_profileApplyChangesButtonMouseClicked

								private void addFriendToGroupButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addFriendToGroupButtonMouseClicked
									if (this.addFriendToGroupButton.isEnabled()) {
										String selectedGroup = (String)this.groupsTable.getModel().getValueAt(this.groupsTable.getSelectedRow(), 0);
										Friend friend = (Friend)this.groupNonMembersList.getSelectedValue();
										Core.getApplication().getDatabaseManager().addNewGroupMember(selectedGroup, friend.getLogin());
										this.updateGroupsTable();
										this.addFriendToGroupButton.setEnabled(false);
									}
								}//GEN-LAST:event_addFriendToGroupButtonMouseClicked

								private void removeFriendFromGroupButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeFriendFromGroupButtonMouseClicked
									if (this.removeFriendFromGroupButton.isEnabled()) {
										String selectedGroup = (String)this.groupsTable.getModel().getValueAt(this.groupsTable.getSelectedRow(), 0);
										Friend friend = (Friend)this.groupMembersList.getSelectedValue();
										Core.getApplication().getDatabaseManager().deleteGroupMembers(selectedGroup, friend.getLogin());
										this.updateGroupsTable();
										this.removeFriendFromGroupButton.setEnabled(false);
									}
								}//GEN-LAST:event_removeFriendFromGroupButtonMouseClicked

								private void removeFriendButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeFriendButtonMouseClicked
									if (this.removeFriendButton.isEnabled()) {
										DefaultTableModel model = (DefaultTableModel)this.myFriendsTable.getModel();
										Friend friend = (Friend)model.getValueAt(this.myFriendsTable.getSelectedRow(), 0);
										try {
											Core.getApplication().getWebserviceManager().doRemove(friend.getLogin());

											DatabaseManager dbm = Core.getApplication().getDatabaseManager();
											Notification newNote = new Notification(new Date(), Notification.SENT_FRIENDSHIP_REMOVED,
															"", friend.getLogin(), friend.getNickname(), this.loginLabel.getText());
											dbm.addNewNotification(newNote);
											this.updateNotifications();

										} catch (WebserviceException ex) {
											Logger.getLogger(MainView.class.getName()).log(Level.SEVERE, null, ex);
										}
									}
								}//GEN-LAST:event_removeFriendButtonMouseClicked

								private void notificationsTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_notificationsTableMouseClicked
									if ( (this.notificationsTable.getSelectedRowCount()==1) && (evt.getButton()==MouseEvent.BUTTON1) )  {
										Integer noteType = (Integer)this.notificationsTable.getModel().getValueAt(this.notificationsTable.getSelectedRow(), 2);
										
										switch (noteType) {
											case Notification.FRIENDSHIP_PROPOSAL:
												this.friendshipProposalPopupMenu.show(this.notificationsTable, evt.getX(), evt.getY()); 
												break;

											case Notification.NOTIFY_FILE:
												this.notifyPopupMenu.show(this.notificationsTable, evt.getX(), evt.getY());
												break;
												
											default:
												this.defaultPopupMenu.show(this.notificationsTable, evt.getX(), evt.getY()); 
												break;
										}// switch
									}// if
								}//GEN-LAST:event_notificationsTableMouseClicked

								private void sharedFilesTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sharedFilesTableMouseClicked
									if ( (this.sharedFilesTable.getSelectedRowCount()==1) && (evt.getButton()==MouseEvent.BUTTON1) ) {
										javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(chelydra.sharelydra.client.Core.class).getContext().getActionMap(MainView.class, this);

										// a menu item for each of our group
										String[] groupNames = Core.getApplication().getDatabaseManager().getGroups().keySet().toArray(new String[0]);
										this.shareFileWithGroupMenu.removeAll();
										for (String group : groupNames) {
											JMenuItem mi = new JMenuItem();
											mi.addActionListener(this);
											mi.setName(group);
											mi.setText(group);
											this.shareFileWithGroupMenu.add(mi);
										}

										// a menu item for each of our friends
										Friend[] friends = Core.getApplication().getFriendManager().getFriends().toArray(new Friend[0]);
										this.shareFileWithFriendMenu.removeAll();
										for (Friend friend : friends) {
											JMenuItem mi = new JMenuItem();
											mi.addActionListener(this);
											mi.setName(friend.getLogin());
											mi.setText(friend.getNickname()+" | "+friend.getName());
											this.shareFileWithFriendMenu.add(mi);
										}

										this.sharedFilePopupMenu.show(this.sharedFilesTable, evt.getX(), evt.getY());
									}// if
								}//GEN-LAST:event_sharedFilesTableMouseClicked

								private void actionPerformedrefreshButton(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionPerformedrefreshButton
                                    // TODO add your handling code here:
                                    System.out.println("Update Friend file list");
                                    this.updateFriendFiles();

}//GEN-LAST:event_actionPerformedrefreshButton

                                private void stopSharingFileMenuItemMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopSharingFileMenuItemMouseClicked
                                    // TODO add your handling code here:
                                }//GEN-LAST:event_stopSharingFileMenuItemMouseClicked

                                private void stopSharingFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopSharingFileMenuItemActionPerformed
                                    // TODO add your handling code here:
                                    FileManager.stopSharingFile(this.getSharedFileSelected());
                                    FileManager.updateFileUI();
                                }//GEN-LAST:event_stopSharingFileMenuItemActionPerformed

																private void searchFilesComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchFilesComboBoxActionPerformed
																	String comboValue = (String)this.searchFilesComboBox.getModel().getSelectedItem();

																	DefaultComboBoxModel model = (DefaultComboBoxModel)this.searchFilesFromComboBox.getModel();
																	model.removeAllElements();
																	this.searchFilesFromComboBox.setEnabled(false);

																	if (comboValue.contentEquals("Group")) {
																		Map<String,Integer> groups = Core.getApplication().getDatabaseManager().getGroups();
																		if (!groups.isEmpty()) {
																			for (String group : groups.keySet())
																				if (groups.get(group)>0)
																					model.addElement(group);
																			if (this.searchFilesComboBox.getModel().getSize()>0)
																				this.searchFilesFromComboBox.setEnabled(true);
																		}

																	} else if (comboValue.contentEquals("Friend")) {
																		Friend[] friends = Core.getApplication().getFriendManager().getConnectedFriends().toArray(new Friend[0]);
																		if (friends.length>0) {
																			for (Friend friend : friends)
																				model.addElement(friend);
																			this.searchFilesFromComboBox.setEnabled(true);
																		}
																	}
																}//GEN-LAST:event_searchFilesComboBoxActionPerformed

																private void profileCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_profileCheckBoxActionPerformed
																	this.profileApplyChangesButton.setEnabled(true);
																	this.profileRevertChangesButton.setEnabled(true);
																}//GEN-LAST:event_profileCheckBoxActionPerformed

																private void downloadFileButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_downloadFileButtonMouseClicked
																	if (this.downloadFileButton.isEnabled()) {
																		DefaultTableModel model = (DefaultTableModel)this.fileFriendTable.getModel();
                                    String fileName = (String) model.getValueAt(this.fileFriendTable.getSelectedRow(),0);
                                    Friend friend = (Friend) model.getValueAt(this.fileFriendTable.getSelectedRow(),2);
                                    int fileId = (Integer) model.getValueAt(this.fileFriendTable.getSelectedRow(),3);
                                    int size = (Integer) model.getValueAt(this.fileFriendTable.getSelectedRow(),1);
                                    System.out.println("Selected login : "+ friend.getLogin()+" fileID "+fileId);
                                    FriendManager fm = Core.getApplication().getFriendManager();
                                    String ipDest = fm.getIpForLogin(friend.getLogin());
                                    int port = fm.getPortForLogin(friend.getLogin());
                                    //port = Core.LocalPortClienttoClient;
                                    System.out.println("Login "+friend.getLogin() +"  IPDest"+ipDest + " port "+port );
                                    try{
                                        DownloadFileThread gFLT = new DownloadFileThread(fileId,size,ipDest,port,fileName); //put back default value(port)
                                        gFLT.start();

                                    }catch(Exception e){
                                        System.out.println("Error while trying to get the File List");
																				e.printStackTrace(System.err);
                                    }
																	}
																}//GEN-LAST:event_downloadFileButtonMouseClicked

																private void fileFriendTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fileFriendTableMouseClicked
																	if (this.fileFriendTable.getSelectedRowCount()==1) {
																		this.downloadFileButton.setEnabled(true);

																	} else {
																		this.downloadFileButton.setEnabled(false);
																	}
																}//GEN-LAST:event_fileFriendTableMouseClicked

																private void searchFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchFilesButtonActionPerformed
																	System.out.println("updating friend's file list");
																	Collection<String> logins = new Vector();
																	if (this.searchFilesFromComboBox.isEnabled()){
																		Object item = this.searchFilesFromComboBox.getModel().getSelectedItem();
																		if (item.getClass().equals(Friend.class)){
																			logins.add(((Friend)item).getLogin());
																		} else if (item.getClass().equals(String.class)){
																			logins.addAll(Core.getApplication().getDatabaseManager().getLoginsOfGroup((String)item));
																		}
																		this.searchFriendFiles(this.searchFilesKeywordsTextField.getText(), logins);
																	} else this.searchFriendFiles(this.searchFilesKeywordsTextField.getText());
																}//GEN-LAST:event_searchFilesButtonActionPerformed

																private void groupMembersListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_groupMembersListMouseClicked
																	this.removeFriendFromGroupButton.setEnabled(true);
																}//GEN-LAST:event_groupMembersListMouseClicked

																private void groupNonMembersListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_groupNonMembersListMouseClicked
																	this.addFriendToGroupButton.setEnabled(true);
																}//GEN-LAST:event_groupNonMembersListMouseClicked

	protected Notification getNotificationSelected() {
		Notification note = null;
		
		if (this.notificationsTable.getSelectedRowCount()==1) {
			DefaultTableModel model = (DefaultTableModel)this.notificationsTable.getModel();
			Integer noteType = (Integer)model.getValueAt(this.notificationsTable.getSelectedRow(), 2);
			Long noteTime = (Long)model.getValueAt(this.notificationsTable.getSelectedRow(), 3);
			note = Core.getApplication().getDatabaseManager().getNotificationForTypeTime(noteType, noteTime);
		}
		
		return note;
	}

	protected String getSharedFileSelected() {
		String file = null;

		if (this.sharedFilesTable.getSelectedRowCount()==1) {
			DefaultTableModel model = (DefaultTableModel)this.sharedFilesTable.getModel();
			file = (String)model.getValueAt(this.sharedFilesTable.getSelectedRow(), 0);
		}

		return file;
	}

	@Action
	public void deleteNotification() {
		if (this.notificationsTable.getSelectedRowCount()==1) {
			DefaultTableModel model = (DefaultTableModel)this.notificationsTable.getModel();
			Integer noteType = (Integer)model.getValueAt(this.notificationsTable.getSelectedRow(), 2);
			Long noteTime = (Long)model.getValueAt(this.notificationsTable.getSelectedRow(), 3);
			Core.getApplication().getDatabaseManager().deleteNotificationForTypeTime(noteType, noteTime);

			this.updateNotifications();
		}
	}

	@Action
	public void acceptFriendshipProposal() {
		Notification note = this.getNotificationSelected();
		if (note!=null) {
			try {
				Core.getApplication().getWebserviceManager().doAccept(note.getSenderLogin());
				DatabaseManager dbm = Core.getApplication().getDatabaseManager();
				dbm.deleteNotificationForTypeTime(note.getType(), note.getCreatedTime().getTime());

				Notification newNote = new Notification(new Date(), Notification.SENT_FRIENDSHIP_ACCEPTED,
								"", note.getSenderLogin(), note.getSenderNickname(), note.getReceiverLogin());
				dbm.addNewNotification(newNote);
				this.updateNotifications();
			} catch (WebserviceException ex) {
				ex.printStackTrace(System.err);
			}
		}
	}

	@Action
	public void declineFriendshipProposal() {
		Notification note = this.getNotificationSelected();
		if (note!=null) {
			try {
				Core.getApplication().getWebserviceManager().doDecline(note.getSenderLogin());
				DatabaseManager dbm = Core.getApplication().getDatabaseManager();
				dbm.deleteNotificationForTypeTime(note.getType(), note.getCreatedTime().getTime());

				Notification newNote = new Notification(new Date(), Notification.SENT_FRIENDSHIP_DECLINED,
								"", note.getSenderLogin(), note.getSenderNickname(), note.getReceiverLogin());
				dbm.addNewNotification(newNote);
				this.updateNotifications();
			} catch (WebserviceException ex) {
				ex.printStackTrace(System.err);
			}
		}
	}
	
	@Action
	public void searchSharedFileAction() {
		Notification note = this.getNotificationSelected();
		if (note!=null) {
			// TODO rechercher un fichier particulier sélectionner dans les notifications
		}
	}

	public void actionPerformed(ActionEvent e) {

		// test with the "tell a group" menu items
		for (int i=0; i<this.shareFileWithGroupMenu.getItemCount(); i++) {
			if (e.getSource().equals(this.shareFileWithGroupMenu.getItem(i))) {
				String groupSelected = this.shareFileWithGroupMenu.getItem(i).getName();
				System.err.println("FOUND GROUP!!!::"+groupSelected);

				String file = this.getSharedFileSelected();
				Core.getApplication().getFriendManager().notifyGroup(groupSelected, file);
			}
		}

		// test with the "tell a friend" menu items
		for (int i=0; i<this.shareFileWithFriendMenu.getItemCount(); i++) {
			if (e.getSource().equals(this.shareFileWithFriendMenu.getItem(i))) {
				String friendSelected = this.shareFileWithFriendMenu.getItem(i).getName();
				System.err.println("FOUND FRIEND!!!::"+friendSelected);

				String file = this.getSharedFileSelected();
				Core.getApplication().getFriendManager().notifyFriend(friendSelected, file);
			}
		}
	}

	// <editor-fold defaultstate="collapsed" desc="Variables declaration">
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem acceptFriendshipMenuItem;
    private javax.swing.JMenu accountMenu;
    private javax.swing.JLabel addAMemberLabel;
    private javax.swing.JButton addFriendToGroupButton;
    private javax.swing.JButton beMyFriendButton;
    private javax.swing.JButton clearSearchFilesButton;
    private javax.swing.JLabel connectedFriendLabel;
    private javax.swing.JScrollPane connectedFriendScrollPane;
    private javax.swing.JList connectedFriendsList;
    private javax.swing.JButton createGroupButton;
    private javax.swing.JMenuItem declineFriendshipMenuItem;
    private javax.swing.JPopupMenu defaultPopupMenu;
    private javax.swing.JMenuItem deleteFriendshipProposalMenuItem;
    private javax.swing.JMenuItem deleteMenuItem;
    private javax.swing.JMenuItem deleteNotifyMenuItem;
    private javax.swing.JMenuItem disconnectMenuItem;
    private javax.swing.JButton downloadFileButton;
    private javax.swing.JLabel downloadsLabel;
    private javax.swing.JScrollPane downloadsScrollPane2;
    private javax.swing.JTable downloadsTable;
    private javax.swing.JMenu editMenu;
    private javax.swing.JLabel emailLabel;
    private javax.swing.JTextField emailTextField;
    private javax.swing.JTable fileFriendTable;
    private javax.swing.JLabel firstNameLabel;
    private javax.swing.JTextField firstNameTextField;
    private javax.swing.JPanel friendAndGroupsPanel;
    private javax.swing.JSeparator friendsAndGroupsSeparator;
    private javax.swing.JPopupMenu friendshipProposalPopupMenu;
    private javax.swing.JButton getFileListButton;
    private javax.swing.JList groupMembersList;
    private javax.swing.JList groupNonMembersList;
    private javax.swing.JLabel groupsLabel;
    private javax.swing.JScrollPane groupsScrollPane;
    private javax.swing.JTable groupsTable;
    private javax.swing.JCheckBox hideEmailCheckBox;
    private javax.swing.JCheckBox hideInSearchCheckBox;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JTable jTable6;
    private javax.swing.JLabel keywordsLabel;
    private javax.swing.JLabel lastNameLabel;
    private javax.swing.JTextField lastNameTextField;
    private javax.swing.JLabel loginLabel;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTabbedPane mainTabbedPanel;
    private javax.swing.JLabel membersLabel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JLabel myFriendsLabel;
    private javax.swing.JScrollPane myFriendsScrollPane;
    private javax.swing.JTable myFriendsTable;
    private javax.swing.JTextField newGroupNameTextField;
    private javax.swing.JLabel nicknameLabel;
    private javax.swing.JTextField nicknameTextField;
    private javax.swing.JLabel notificationsLabel;
    private javax.swing.JTable notificationsTable;
    private javax.swing.JPopupMenu notifyPopupMenu;
    private javax.swing.JPanel overviewPanel;
    private javax.swing.JButton profileApplyChangesButton;
    private javax.swing.JPanel profilePanel;
    private javax.swing.JButton profileRevertChangesButton;
    private javax.swing.JButton refreshButton;
    private javax.swing.JButton refreshOverviewButton;
    private javax.swing.JButton removeFriendButton;
    private javax.swing.JButton removeFriendFromGroupButton;
    private javax.swing.JButton removeGroupButton;
    private javax.swing.JButton searchFilesButton;
    private javax.swing.JComboBox searchFilesComboBox;
    private javax.swing.JComboBox searchFilesFromComboBox;
    private javax.swing.JTextField searchFilesKeywordsTextField;
    private javax.swing.JPanel searchFilesPanel;
    private javax.swing.JButton searchFriendsButton;
    private javax.swing.JTextField searchFriendsKeywordsTextField;
    private javax.swing.JPanel searchFriendsPanel;
    private javax.swing.JButton searchFriendsResetButton;
    private javax.swing.JTable searchFriendsTable;
    private javax.swing.JScrollPane searchResultScrollPane;
    private javax.swing.JMenuItem searchSharedFileMenuItem;
    private javax.swing.JTabbedPane searchTabbedPanel;
    private javax.swing.JButton shareAnotherFileButton;
    private javax.swing.JMenu shareFileWithFriendMenu;
    private javax.swing.JMenu shareFileWithGroupMenu;
    private javax.swing.JPopupMenu sharedFilePopupMenu;
    private javax.swing.JPanel sharedFilesPanel;
    private javax.swing.JScrollPane sharedFilesScrollPane;
    private javax.swing.JTable sharedFilesTable;
    private javax.swing.JMenuItem stopSharingFileMenuItem;
    private javax.swing.JMenu toolsMenu;
    private javax.swing.JLabel transfertLabel;
    private javax.swing.JPanel transfertsPanel;
    private javax.swing.JScrollPane transfertsScrollPane;
    private javax.swing.JSeparator transfertsSeparator;
    private javax.swing.JTable transfertsTable;
    private javax.swing.JButton updateFriendsButton;
    private javax.swing.JLabel uploadsLabel;
    private javax.swing.JScrollPane uploadsScrollPane;
    private javax.swing.JTable uploadsTable;
    private javax.swing.JLabel userLoginLabel;
    // End of variables declaration//GEN-END:variables
	// </editor-fold>

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}

